{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-04-07T09:10:44.612917600Z",
     "start_time": "2024-04-07T09:10:29.244688100Z"
    }
   },
   "outputs": [
    {
     "ename": "FileNotFoundError",
     "evalue": "[Errno 2] No such file or directory: './../../hubconf.py'",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mFileNotFoundError\u001B[0m                         Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[5], line 3\u001B[0m\n\u001B[0;32m      1\u001B[0m \u001B[38;5;28;01mimport\u001B[39;00m \u001B[38;5;21;01mtorch\u001B[39;00m\n\u001B[1;32m----> 3\u001B[0m model \u001B[38;5;241m=\u001B[39m \u001B[43mtorch\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mhub\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mload\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[38;5;124;43m./../../\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[38;5;124;43myolov5s\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43msource\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[38;5;124;43mlocal\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[43m)\u001B[49m\n\u001B[0;32m      5\u001B[0m image \u001B[38;5;241m=\u001B[39m \u001B[38;5;124m'\u001B[39m\u001B[38;5;124m../../data/videos/riskvideo.mp4\u001B[39m\u001B[38;5;124m'\u001B[39m\n\u001B[0;32m      7\u001B[0m results \u001B[38;5;241m=\u001B[39m model(image)\n",
      "File \u001B[1;32mD:\\anaconda\\yolov5\\lib\\site-packages\\torch\\hub.py:566\u001B[0m, in \u001B[0;36mload\u001B[1;34m(repo_or_dir, model, source, trust_repo, force_reload, verbose, skip_validation, *args, **kwargs)\u001B[0m\n\u001B[0;32m    562\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m source \u001B[38;5;241m==\u001B[39m \u001B[38;5;124m'\u001B[39m\u001B[38;5;124mgithub\u001B[39m\u001B[38;5;124m'\u001B[39m:\n\u001B[0;32m    563\u001B[0m     repo_or_dir \u001B[38;5;241m=\u001B[39m _get_cache_or_reload(repo_or_dir, force_reload, trust_repo, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mload\u001B[39m\u001B[38;5;124m\"\u001B[39m,\n\u001B[0;32m    564\u001B[0m                                        verbose\u001B[38;5;241m=\u001B[39mverbose, skip_validation\u001B[38;5;241m=\u001B[39mskip_validation)\n\u001B[1;32m--> 566\u001B[0m model \u001B[38;5;241m=\u001B[39m \u001B[43m_load_local\u001B[49m\u001B[43m(\u001B[49m\u001B[43mrepo_or_dir\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mmodel\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[43margs\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[43mkwargs\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    567\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m model\n",
      "File \u001B[1;32mD:\\anaconda\\yolov5\\lib\\site-packages\\torch\\hub.py:592\u001B[0m, in \u001B[0;36m_load_local\u001B[1;34m(hubconf_dir, model, *args, **kwargs)\u001B[0m\n\u001B[0;32m    590\u001B[0m \u001B[38;5;28;01mwith\u001B[39;00m _add_to_sys_path(hubconf_dir):\n\u001B[0;32m    591\u001B[0m     hubconf_path \u001B[38;5;241m=\u001B[39m os\u001B[38;5;241m.\u001B[39mpath\u001B[38;5;241m.\u001B[39mjoin(hubconf_dir, MODULE_HUBCONF)\n\u001B[1;32m--> 592\u001B[0m     hub_module \u001B[38;5;241m=\u001B[39m \u001B[43m_import_module\u001B[49m\u001B[43m(\u001B[49m\u001B[43mMODULE_HUBCONF\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mhubconf_path\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    594\u001B[0m     entry \u001B[38;5;241m=\u001B[39m _load_entry_from_hubconf(hub_module, model)\n\u001B[0;32m    595\u001B[0m     model \u001B[38;5;241m=\u001B[39m entry(\u001B[38;5;241m*\u001B[39margs, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mkwargs)\n",
      "File \u001B[1;32mD:\\anaconda\\yolov5\\lib\\site-packages\\torch\\hub.py:106\u001B[0m, in \u001B[0;36m_import_module\u001B[1;34m(name, path)\u001B[0m\n\u001B[0;32m    104\u001B[0m module \u001B[38;5;241m=\u001B[39m importlib\u001B[38;5;241m.\u001B[39mutil\u001B[38;5;241m.\u001B[39mmodule_from_spec(spec)\n\u001B[0;32m    105\u001B[0m \u001B[38;5;28;01massert\u001B[39;00m \u001B[38;5;28misinstance\u001B[39m(spec\u001B[38;5;241m.\u001B[39mloader, Loader)\n\u001B[1;32m--> 106\u001B[0m \u001B[43mspec\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mloader\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mexec_module\u001B[49m\u001B[43m(\u001B[49m\u001B[43mmodule\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    107\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m module\n",
      "File \u001B[1;32m<frozen importlib._bootstrap_external>:839\u001B[0m, in \u001B[0;36mexec_module\u001B[1;34m(self, module)\u001B[0m\n",
      "File \u001B[1;32m<frozen importlib._bootstrap_external>:975\u001B[0m, in \u001B[0;36mget_code\u001B[1;34m(self, fullname)\u001B[0m\n",
      "File \u001B[1;32m<frozen importlib._bootstrap_external>:1032\u001B[0m, in \u001B[0;36mget_data\u001B[1;34m(self, path)\u001B[0m\n",
      "\u001B[1;31mFileNotFoundError\u001B[0m: [Errno 2] No such file or directory: './../../hubconf.py'"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "\n",
    "model = torch.hub.load('./../../', 'yolov5s', source='local')\n",
    "\n",
    "image = '../../data/videos/riskvideo.mp4'\n",
    "\n",
    "results = model(image)\n",
    "\n",
    "print(results)\n",
    "results.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "2295db6f8f3854e0"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
